#version 330 core

layout(location = 0)out vec4 color;
struct Light {
    vec3 position;
    vec3 ambient;
    vec3 diffuse;
    vec3 specular;
};
struct Material {
    vec3 ambient;
    vec3 diffuse;
    vec3 specular;
    float shininess;
};
in vec3 FragPos;
in vec3 Normal;

uniform vec3 viewPos;
uniform Material material;
uniform Light light;


void main()
{
    vec3 norm = normalize(Normal);
    vec3 lightDir = normalize(light.position - FragPos);
    vec3 viewDir = normalize(viewPos - FragPos);
    vec3 reflectDir = reflect(-lightDir, norm);


    float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
    vec3 specular = material.specular * spec * light.specular;

    float diff = max(dot(norm, lightDir), 0.0);
    vec3 diffuse = diff * (light.diffuse*material.diffuse);


    vec3 ambient = material.ambient * light.ambient;

    vec3 result = ambient+diffuse+specular;
    color = vec4(result, 1.0);
}